#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include "PPLConfig.h"
#include "ParseEngine.h"
#include "GlobalCounter.h"

void sigIntHandler(int);

GlobalCounter gCounter;

int main()
{
	printf("-------------------------\n");
	printf("Packet Parser Lite !!!\n");
	printf("\t\tBy dUKE\n");
	printf("-------------------------\n");
	sleep(1);

	if(SIG_ERR == signal(SIGINT, sigIntHandler))
	{
		printf("Error: Set SIGINT Handler Fail!\n");
		return -1;
	}

	PPLConfig::getInstance();

	memset(&gCounter, 0, sizeof(GlobalCounter));

	ParseEngine aParseEngine;
	if(0 > aParseEngine.run())
	{
		printf("Critical Error: Run Parse Engine Fail!\n");
		return -1;
	}

	printf("httpResCount = %llu, htmlCount = %llu, headStartCount = %llu, headEndCount = %llu, fullHeadAndResOK = %lld, keywordsCount = %llu, descriptionCount = %llu, tcpHeadCount = %lld\n", gCounter.httpResCount, gCounter.htmlCount, gCounter.headStartCount, gCounter.headEndCount, gCounter.resOK, gCounter.keywordsCount, gCounter.descriptionCount, gCounter.tcpHeadCount);

	return 0;
}

void sigIntHandler(int signo)
{
	printf("httpResCount = %llu, htmlCount = %llu, headStartCount = %llu, headEndCount = %llu, fullHeadAndResOK = %lld, keywordsCount = %llu, descriptionCount = %llu, tcpHeadCount = %lld\n", gCounter.httpResCount, gCounter.htmlCount, gCounter.headStartCount, gCounter.headEndCount, gCounter.resOK, gCounter.keywordsCount, gCounter.descriptionCount, gCounter.tcpHeadCount);
	exit(0);
}
